package com.supermap.dataservice.cloud.chinatemplate;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @author aqua
 * @description
 * @date 2018年12月11 下午 7:04
 * @email 1301584033@qq.com
 */
@Mapper
public interface ChinaTemplateMpper {
    /**
     *产品组
     * */
    @Select("select t1.id,t1.group_name as groupName,date_format(t1.create_date,'%Y-%m-%d %H:%i:%S') as createDate from t_b_productgroup t1   \n" +
            "where position(#{areaCode} in fit_areaid ) and t1.content_category=#{templateId}\n")
    List<Map<String,Object>> getProductGrupByTemplateId(@Param("areaCode")Integer areaCode, @Param("templateId")Integer templateId);

    @Select("SELECT templateId,name as templateName,if(t2.content_category is null,0,1) isdefault  FROM china_pamiss.t_producttemplate t1\n" +
            "left join \n" +
            "(select content_category from\n" +
            "(select t2.content_category,t1.create_date from  china_pamiss.t_b_pms_product t1\n" +
            "inner join china_pamiss.t_b_productgroup t2 on t1.product_group = t2.id and t1.product_state =6\n" +
            "union \n" +
            "select t2.content_category,t1.create_date from  cqpamiss.t_b_pms_product t1\n" +
            "inner join cqpamiss.t_b_productgroup t2 on t1.product_group = t2.id and t1.product_state =6) u\n" +
            "order by u.create_date desc \n" +
            "limit 1) t2\n" +
            "on t1.templateId = t2.content_category\n" +
            "WHERE if(#{areaCode} is not null,areacode = left(#{areaCode},2), areaCode is null ) and DEL_FLG=0\n" +
            "order by templateId")
    List<Map<String,Object>> getListProductTemplate(@Param("areaCode")Integer areaCode);

    @Select("select id,create_name,create_by,UNIX_TIMESTAMP(create_date) as create_date,update_name,update_by,UNIX_TIMESTAMP(update_date) as update_date,sys_org_code,sys_company_code,bpm_status,product_name,id_code,product_group,product_state,product_maker,product_unit,product_type,UNIX_TIMESTAMP(product_check_date) as product_check_date,product_check_person,product_summary,product_title,product_mainpic,product_from_where,folder_name,product_read_count,product_praise_times,product_ncomment_times,product_group_name,product_maker_name, UNIX_TIMESTAMP(make_date) as make_date from t_b_pms_product where product_group=#{productgroupId}")
    List<Map<String,Object>> getProduct(@Param("productgroupId")String productgroupId);

}
